package com.objetdirect.gwt.umldrawer.server.services;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.objetdirect.gwt.umldrawer.server.dao.TasksDao;
import com.objetdirect.gwt.umldrawer.shared.dto.ProjectDto;
import com.objetdirect.gwt.umldrawer.shared.dto.TasksDto;
import com.objetdirect.gwt.umldrawer.shared.services.TasksService;

@Service("taskService")
public class TasksServiceImpl implements TasksService {

	@Autowired
	private TasksDao tasksDao;

	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void distroy() {
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void addTask(int projectId, String taskName, String taskContent)
			throws Exception {
		
		ProjectDto project = new ProjectDto(projectId);
		TasksDto task = new TasksDto(taskName, taskContent, project);
		tasksDao.persist(task);
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<TasksDto> getTasks(int projectId) throws Exception {
		
		return null;
	}

	@Override
	public void removeTask(int projectId) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
